/**
 * Created by shizhonghai on 2016/7/7 0007.
 */

app.directive('imageUpload', ['fileUploadServices','messageServices', 'imgModalServices', function(fileUploadServices,messageServices,imgModalServices) {
    return{
        restrict:'EA',
        templateUrl: 'tpl/modal/imageModel.html',
        ransclude: true,
        scope: {
            imageslist: '='
        },
        link: function(scope) {
            // 上传图片
            scope.openFileUpload = function () {
                //操作返回
                fileUploadServices.uploadFile(false).then(function (selectedItem) {
                    if(scope.imageslist == undefined ) {
                        scope.imageslist = [];
                    }
                    scope.imageslist = scope.imageslist.concat(selectedItem);
                }, function () {});
            };

            // 删除图片
            scope.delImage = function(index) {
                messageServices.openShowMessage("警告","确定删除此需求图片?").then(function () {
                    delete scope.imageslist.splice(index,1);
                });
            };

            // 显示图片
            scope.showImg = function (title, img) {
                imgModalServices.showImg(title, img);
            };
        }
    };
}]);
